#include "Messaging.h"
#include "BaseObject.hpp"

void Messenger::SendMessageA(eMessage Type,float const & Info,int const & ReceiverID)
{
	float * Temp = new float [1];
	int * Temp1 = new int [1];
	Temp[0] = (float)Info;
	Temp1[0] = ReceiverID;
	Message* NewMessage = new Message(Type,Temp,Temp1);
	AllMessages.add(NewMessage);
	AllMessages.sort();
}

void Messenger::ReceiveMessages(void* Receiver)
{
	int *i = new int[AllMessages.getSize()];
	for(int j = 0;j < AllMessages.getSize();++j)
	{
		if(((BaseObject*)Receiver)->m_iID == *(AllMessages.get(j)->ReceiverID))
		{
			i[j] = j;
			Message * New = AllMessages.get(j);
			((BaseObject*)Receiver)->GetMessageA(New);
		}
	}
	delete i;
	AllMessages.sort();
}

void Messenger::ClearMessage(Message* Msg)
{
	AllMessages.remove(Msg);
	AllMessages.sort();
	delete Msg;
}


